package Template5::Info::Element;

use strict;
use warnings;

use Template5::Info::Tagmaps;

#-------------------------------------------------------------------------------
#private static
our $__singleton = undef;

#public
sub new()
{
	my $class = shift;	

	if(!defined($__singleton))
	{
		$__singleton = bless({}, $class);
	};
	
	return $__singleton;
};

#-------------------------------------------------------------------------------
#public
sub element_create($$$$)
{
	my $this      = shift;
	my $name      = shift;
	my $hHTMLNode = shift;
	my $params    = shift;
	my $traverser = shift;
	
	my $retVal       = undef;
	my $elmclassname = $Template5::Info::Tagmaps::classes{$name};

	if(defined($elmclassname))
	{
		eval "require $elmclassname;";
		$retVal = $elmclassname->new($hHTMLNode, $params);
		
  	if($retVal->isa('Template5::Info::Element::Info'))
  	{
  		for(my $node; $node = $traverser->next();)
  		{
  			my($hTMLInfoNodeChild, $hHTMLNodeChild) = @{$node};
  			my ($prefix, $name) = split(/\:/, $hHTMLNodeChild->tag(), 2);
  			$retVal->set_value($name?$name:$prefix, $hTMLInfoNodeChild);

  			#print $hHTMLNodeChild->tag();
  			#print "\n";  			
  		};
  	};
	};

	return $retVal;
};

1;

